var express = require('express');
var router = express.Router();
//get：表示查询
router.get("/student",(req,res)=>{
    res.json({"res":"查询"})
});
//post ：添加
router.post("/student",(req,res)=>{
    let {name,gender,age,classId} =req.body 
    console.log(name,gender,age,classId);
    res.json({"res":"添加","res":req.body})

});
//put ：修改学生
router.put("/student",(req,res)=>{
    res.json({"res":"修改","data":req.body})
});
//delete ：删除
router.delete("/student",(req,res)=>{
    res.json({"res":"删除"})
});
//rest风格的参数（路径参数）
//参数的风格  冒号+参数名
/* router.get("/student/:studentId",(req,resp)=>{
    //restful的参数使用 req.params)来获得
    //resp.json(req.params)
    let {studentId} =req.params; 
}) */
//传参时 要注意顺序
router.get("/student/:id/:name",(req,resp)=>{
    //restful的参数使用 req.params)来获得
    let {id,name} =req.params; 
    resp.json(req.params) 
})


module.exports = router;

